home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 5_5.lha / 5_5 / 5_5a2.c < prev    next >
Text File  |  1993-08-08  |  845b  |  36 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. tatic void get_token(istream &input)
  6.  
  7.    char ch;
  8.    do  {    // skip whitespace
  9. if (!input.get(ch))
  10.     { curr_tok.type = END; return; }
  11.    } while (isspace(ch));
  12.  
  13.    switch (ch)
  14. {
  15. case '*': case '/': case '+': case '-':
  16. case '(': case ')':
  17.     curr_tok.type = ch;
  18. f (debug) cout << "get_token() returns '" << chr(ch) << "'\n"; // DELETE
  19.     return;
  20.  
  21. case '0': case '1': case '2': case '3':
  22. case '4': case '5': case '6': case '7':
  23. case '8': case '9':
  24.     input.putback(ch);
  25.     input >> curr_tok.value;
  26.     curr_tok.type = NUMBER;
  27. f (debug) cout << "get_token() returns NUMBER='" << curr_tok.value << "'\n"; // DELETE
  28.     return;
  29.  
  30. default:
  31.     error("bad token");
  32.     curr_tok.type = END;
  33.     return;
  34. }
  35.  
  36.